package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.hibernate.internal.util.type.PrimitiveWrapperHelper.IntegerDescriptor;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.model.Cuser;
import com.zr.service.RemoveUsersService;

public class RemoveUsersAction extends ActionSupport implements ServletResponseAware,SessionAware,ServletRequestAware{
	
	 private HttpServletResponse resp;
	 private  Map<String,Object> session; 
	 private HttpServletRequest req;
		@Override
		public void setSession(Map<String, Object> session) {
			this.session = session;
		}

		@Override
		public void setServletResponse(HttpServletResponse response) {
			this.resp = response;
		}
		
		@Override
		public void setServletRequest(HttpServletRequest request) {
			this.req = request;
		}
		
		@Resource
		private RemoveUsersService removeUsersService;
		
		public void removeUsers(){
			String uids = req.getParameter("uid");
			int uid = Integer.parseInt(uids);
			Cuser u = (Cuser)session.get("cuser");
			int cuid = u.getUid();
			String cuname = u.getUname();
		    int i = removeUsersService.getRemovedOrNot(uid);
		    try {
				PrintWriter pw = resp.getWriter();
				 if (i==1) {
					    removeUsersService.removeUsersByUid(uid, cuname, cuid);
						pw.write("1");
						pw.flush();
						pw.close();
					}else if(i==2){
						pw.write("2");
						pw.flush();
						pw.close();
					} else {
						pw.write("0");
						pw.flush();
						pw.close();
					}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
		
	

}
